Return to doc.sitecore.com

Advanced Item Auditing
Prev Next

Author: Jesper Jørgensen
Posted: 6/19/2006 3:41:24 PM

In v5.1 and 5.2, Sitecore offers audit logging of changes to items performed through the UI. On some installations you may want to log other changes like API updates etc. as well. This article describes how this can be accomplished. 

The following file: audit.zip contains two files:

  1. Trigger.sql
    If you backup your master database and apply this script (after reviewing table owner etc. is correct), all updates and deletes to items in the master database will be logged in the new table MasterLog. Id, Name, Action and Time will be logged for the event. You will not necessarily know what codepart or user triggered the event, but knowing this info could anyhow be usefull to pinpouint what happened to the item. It will also log if other applications (Query Analyzer, Sitecore, you name it) is updating this database. The sql could easily be updated to also work with changes in the web database etc.
    Note: In v5.3, Sitecore also saves changes to items in the History table. You should add triggers to this table or use it directly.
  2. Eventhandler.zip
    This file includes a project as well as dll, that allows you to hook into e.g. the item:deleted event in web.config, which is fired for API level deleting of items. The code can be customized to any of the existing events you may want but comes default for item:saved and item:deleted. By applying the following changes: 

Changes to web.config file:

Add the following line to the <event name="item:deleted"> section:

< handler type = "Eventhandler.Logitem, Eventhandler"method="OnItemDeleted" /> 

Add the following line to the <event name="item:saved"> section:

< handler type = "Eventhandler.Logitem, Eventhandler"method="OnItemSaved" /> 

You will get info in your logfile about the items these events fire on. As they will fire for any Sitecore database, you may want to customize the code so only e.g. events for the master database are logged.


Prev Next